/*
 * Security.hpp
 *
 *  Created on: Jan 14, 2015
 *      Author: wasp
 */

#include <huctx.h>
#include <hurandom.h>
#include <openssl/ossl_typ.h>
#include <openssl/rsa.h>
#include <qfile.h>

#ifndef SECURITY_HPP_
#define SECURITY_HPP_


namespace de
{
    namespace heimweghelden
    {
        namespace tracking
        {

            class Security: public QObject
            {
            public:
                static Security* getInstance();
                static void freeall();
                bool encrypt(QString input, unsigned char *output);
                int encryptSize();
                bool decrypt(QString input, unsigned char *output);
            private:
                Security();
                bool init();
                virtual ~Security();
                void save(BUF_MEM* buf, QString name);
                void dump(BUF_MEM* buf);
                void show();
                void zero(size_t** s);
                void allocate(size_t** s, unsigned char *** c);
                void toBN(size_t ** s, unsigned char *** c, BIGNUM *** b);
                void destroy(unsigned char *** c);
                void destroy(BIGNUM *** b);
                int rsaGenerateAndExport(sb_Params &rsaParams);
                bool loadKeys(QFile* keyFilePriv, QFile* keyFilePub);

                static Security* _instance;
                sb_GlobalCtx sbCtx;
                sb_Params rsaParams;
                sb_PrivateKey privateKey;
                sb_PublicKey publicKey;
                RSA* keystore;
            };

        } /* namespace tracking */
    } /* namespace heimweghelden */
} /* namespace de */

#endif /* SECURITY_HPP_ */
